package com.mer.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mer.entity.Order;
import com.mer.mapper.OrderMapper;
import com.mer.service.OrderService;
import com.mer.vo.CommonResult;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @program: IIPhase-project
 * @description: 订单实现类
 * @author: 张庆恒
 * @create: 2021-10-22 11:17
 **/
@Service
public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements OrderService {
    @Resource
    private OrderMapper orderMapper;
    /**
     * 查询全部订单根据条件
     *
     * @param page
     * @param limit
     * @param order
     * @return
     */
    @Override
    public CommonResult getAllOrder(Integer page, Integer limit, Order order) {
        Page<Order> oPage = new Page<>(page, limit);
        QueryWrapper<Order> wrapper = new QueryWrapper<>();
        if (StringUtils.isNotEmpty(order.getMobile())) {
            wrapper.eq("tor.mobile", order.getMobile());
        }
        if (StringUtils.isNotEmpty(order.getOrderNo())) {
            wrapper.eq("tor.order_no", order.getOrderNo());
        }
        if (StringUtils.isNotEmpty(order.getTeacherName())) {
            wrapper.like("teacher_name", order.getTeacherName());
        }
        if (order.getStatus() != null) {
            wrapper.eq("tor.status", order.getStatus());
        }
        if (order.getPayType() != null) {
            wrapper.eq("tor.pay_type", order.getPayType());
        }
        if (StringUtils.isNotEmpty(order.getGmtCreate())) {
            wrapper.gt("tor.gmt_modified", order.getGmtCreate());
        }
        if (StringUtils.isNotEmpty(order.getGmtModified())) {
            wrapper.le("tor.gmt_modified", order.getGmtModified());
        }
        if (StringUtils.isNotEmpty(order.getCourseTitle())) {
            wrapper.like("course_title", order.getCourseTitle());
        }
        Page<Order> orderPage = orderMapper.getAllOrder(oPage, wrapper);
        return new CommonResult(2000, "查询成功", orderPage);
    }
}
